#coding:utf8
'''
[2,3,6,7] target=7
[7]
[2,2,3]

解题思路是深度优先搜索
'''

class Solution(object):
    def combinationSum(self, candidates, target):
        res = []
        self.dfs(candidates, target, 0, [], res)
        return res

    def dfs(self, cans, target, index, path, res):
        if target < 0:
            return
        if target == 0:
            res.append(path)
            return
        for i in range(index, len(cans)):
            self.dfs(cans, target-cans[i], i, path+[cans[i]], res)

can = [2,3,6,7]
target = 7
s= Solution()
print s.combinationSum(can, target)
